package ControlLayer;

import java.sql.Date;
import java.util.ArrayList;

import DBLayer.DBSales;
import ModelLayer.Sales;



public class CtrSale {
	
	DBSales dbSales;
	
	public CtrSale(){
		dbSales = new DBSales();
	}

	
	public void addProduct(Sales sale, int prid, int quantity){
		sale.addProduct(prid, quantity);
	}
	
	public void removeProduct(Sales sale, int prid){
		sale.removeProduct(prid);
	}
	
	
	public ArrayList<Sales> getAll(){
		return dbSales.getAll();
	}
	
	public ArrayList<Sales> getAll_byCustomerID(int cid){
		return dbSales.getAll_byCustomerID(cid);
	}
	
	
	public Sales find(int invoiceNo) {
		return dbSales.find(invoiceNo);
	}	
	
	
	public int delete(int invoiceNo){
		return dbSales.delete(invoiceNo);
	}
	
	
	public int update(int invoiceNo, Date date, double amount,int cid, String deliveryStatus, Date deliveryDate)
	{
		Sales sale = new Sales(invoiceNo, date, amount, cid, deliveryStatus, deliveryDate);
		return dbSales.update(sale);
	}
	
	public int insert(double amount,int cid, String deliveryStatus, Date deliveryDate)
	{
		Date date = new Date( (new java.util.Date()).getTime() );
		
		Sales sale = new Sales(-1, date, amount, cid, deliveryStatus, deliveryDate);
		
		int rc = -1;
		try {
			rc = dbSales.insert(sale);
		} catch (Exception e) {
			System.err.println("Could not create sale CTRLayer");
		}
		
		return rc;
	}
	
}
